<template>
  <div>
    <div v-show="!isShowLog">
      <jxf-titletip :title="title" :hasGoBack="true" :hasRefresh="false" @goBack="goListPage"></jxf-titletip>
      <div class="jxf-content mt20">
        <el-form :rules="rules">
          <el-card class="jxf-table-card mt10">
            <div slot="header" class="clearfix">
              <span>采购商信息</span>
              <!-- 副标题 -->
              <!-- 按钮 -->
              <div>
                <!--<el-button type="primary" @click="" v-if="detailInfo.status === 0">查看电子合同</el-button>-->
                <el-button type="primary" @click="editInfo" v-if="detailInfo.status === 0 && isShowBtns" :disabled="detailInfo.merchantInfo[2].isEdit">编辑</el-button>
                <el-button type="primary" @click="showPass" v-if="detailInfo.status === 0 && detailInfo.page !== 1 && isShowBtns" :disabled="detailInfo.merchantInfo[2].isEdit">审批通过</el-button>
                <el-button type="primary" @click="showNotPass" v-if="detailInfo.status === 0 && detailInfo.page !== 1 && isShowBtns" :disabled="detailInfo.merchantInfo[2].isEdit">审批驳回</el-button>
                <el-button type="primary" @click="watchAccountInfo" v-if="detailInfo.page === 1" :disabled="detailInfo.merchantInfo[2].isEdit">查看账户信息</el-button>
                <el-button type="primary" @click="getLog" v-if="detailInfo.page === 1" :disabled="detailInfo.merchantInfo[2].isEdit">查看登录日志</el-button>
                <el-button type="primary" @click="showNotMerchant" v-if="detailInfo.page === 1 && detailInfo.accountStatus == 1 && isShowBtns" :disabled="detailInfo.merchantInfo[2].isEdit">禁用采购商</el-button>
                <el-button type="primary" @click="showMerchant" v-if="detailInfo.page === 1 && detailInfo.accountStatus == 0 && isShowBtns" :disabled="detailInfo.merchantInfo[2].isEdit">启用采购商</el-button>
              </div>
            </div>
            <div class="listArea">
              <jxf-datalist :info="detailInfo.merchantInfo" :lineNum="2">
                <template slot="telphone" slot-scope="merchantInfo">
                  <div class="jxf-flex-start">
                    {{merchantInfo.info.value}}
                    <el-button type="text" v-if="detailInfo.status === 0" @click="resetPwd">重置密码</el-button>
                  </div>
                </template>
                <template slot="enterpriseName" slot-scope="merchantInfo">
                  <div class="jxf-flex-start" v-if="!merchantInfo.info.isEdit">
                    {{merchantInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="merchantInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="contact" slot-scope="merchantInfo">
                  <div class="jxf-flex-start" v-if="!merchantInfo.info.isEdit">
                    {{merchantInfo.info.value ? merchantInfo.info.value : "无"}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="merchantInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="detailAdress" slot-scope="merchantInfo">
                  <div class="jxf-flex-start" v-if="!merchantInfo.info.isEdit">
                    {{merchantInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="merchantInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="status" slot-scope="merchantInfo">
                  <div class="jxf-flex-start">
                    <div v-if="merchantInfo.info.value == 0">待审核</div>
                    <div v-if="merchantInfo.info.value == 1">审核通过</div>
                    <div v-if="merchantInfo.info.value == 2">审核驳回</div>
                  </div>
                </template>
                <template slot="Branch" slot-scope="merchantInfo">
                  <div class="jxf-flex-start">
                    {{merchantInfo.info.value}}
                    <!--<el-button type="text" @click="showFenSetting" v-if="detailInfo.status === 0">变更所属分公司</el-button>-->
                  </div>
                </template>
                <template slot="salesmanName" slot-scope="merchantInfo">
                  <div class="jxf-flex-start">
                    {{merchantInfo.info.value}}
                    <el-button type="text" @click="showSalemanSetting" v-if="detailInfo.merchantInfo[2].isEdit && detailInfo.status === 0 && detailInfo.page !== 1">设置对接业务员</el-button>
                  </div>
                </template>
                <template slot="channelDealerName" slot-scope="merchantInfo">
                  <div class="jxf-flex-start">
                    {{merchantInfo.info.value}}
                    <el-button type="text" @click="showChannelSetting" v-if="detailInfo.merchantInfo[2].isEdit && detailInfo.status === 0 && detailInfo.page !== 1">设置对接渠道商</el-button>
                  </div>
                </template>
                <template slot="creditCode" slot-scope="merchantInfo">
                  <div class="jxf-flex-start" v-if="!merchantInfo.info.isEdit">
                    {{merchantInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="merchantInfo.info.value" clearable></el-input>
                  </div>
                </template>
              </jxf-datalist>
            </div>
          </el-card>
          <el-card class="jxf-table-card mt10">
            <div slot="header" class="clearfix">
              <span>其他信息</span>
            </div>
            <div class="listArea">
              <jxf-datalist :info="detailInfo.otherInfo" :lineNum="2">
                <template slot="subjectPerson" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="!otherInfo.info.isEdit">
                    {{otherInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="otherInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="registeredIDNumber" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="!otherInfo.info.isEdit">
                    {{otherInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-form-item>
                      <el-input v-model="otherInfo.info.value" clearable></el-input>
                    </el-form-item>
                  </div>
                </template>
                <template slot="legalName" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="!otherInfo.info.isEdit">
                    {{otherInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="otherInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="idNumber" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="!otherInfo.info.isEdit">
                    {{otherInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="otherInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="certificateValidity" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="!otherInfo.info.isEdit">
                    {{otherInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-row :gutter="10">
                      <el-col :span="12">
                        <el-date-picker
                          v-model="detailInfo.identityCardStart"
                          type="date"
                          :picker-options="pickerStart"
                          placeholder="选择日期"
                          format="yyyy 年 MM 月 dd 日"
                          value-format="yyyy/MM/dd">
                        </el-date-picker>
                      </el-col>
                      <el-col :span="12">
                        <el-date-picker
                          v-model="detailInfo.identityCardEnd"
                          type="date"
                          placeholder="选择日期"
                          :picker-options="pickerEnd"
                          format="yyyy 年 MM 月 dd 日"
                          value-format="yyyy/MM/dd">
                        </el-date-picker>
                      </el-col>
                    </el-row>
                  </div>
                </template>
                <template slot="identityCard" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="!otherInfo.info.isEdit">
                    {{otherInfo.info.value}}
                  </div>
                  <div class="jxf-flex-start" v-else>
                    <el-input v-model="otherInfo.info.value" clearable></el-input>
                  </div>
                </template>
                <template slot="auditTime" slot-scope="otherInfo">
                  <div class="jxf-flex-start">
                    {{otherInfo.info.value ? FormatDate.timeFormat(otherInfo.info.value) : ""}}
                  </div>
                </template>
                <template slot="cardNo" slot-scope="otherInfo">
                  <div class="jxf-flex-start" v-if="otherInfo.info.value">
                    {{otherInfo.info.value.substring(0, 3)}}****{{otherInfo.info.value.substring(otherInfo.info.value.length - 4, otherInfo.info.value.length)}}
                  </div>
                </template>
              </jxf-datalist>
            </div>
          </el-card>
          <el-card class="jxf-table-card mt10">
            <div slot="header" class="clearfix">
              <span>*原始资料</span>
            </div>
            <div class="listArea">
              <el-row :gutter="10">
                <el-col :xs="12" :sm="12" :md="8" :lg="6" :xl="4" v-if="(detailInfo.identityCard.value && detailInfo.identityCard.value.split(',')[0]) || this.detailInfo.merchantInfo[2].isEdit">
                  <div class="imgArea">
                    <!--<img :src="detailInfo.identityCard.value.split(',')[0]"/>-->
                    <viewer :images="detailInfo.identityCard.value && detailInfo.identityCard.value.split(',')[0] ? detailInfo.identityCard.value.split(',')[0].split(',') : []">
                      <div><img :src="detailInfo.identityCard.value.split(',')[0]"></div>
                    </viewer>
                    <div class="operateBtn"   v-if="detailInfo.merchantInfo[2].isEdit">
                      <el-button type="text" size="small" @click="showFrontCardCropper">点击上传</el-button>
                      <el-button size="small" type="text" @click="deleteFrontImg">删除</el-button>
                    </div>
                    <div class="imageBottom">法人身份证正面</div>
                  </div>
                </el-col>
                <el-col :xs="12" :sm="12" :md="8" :lg="6" :xl="4" v-if="(detailInfo.identityCard.value && detailInfo.identityCard.value.split(',')[1]) || this.detailInfo.merchantInfo[2].isEdit">
                  <div class="imgArea">
                    <viewer :images="detailInfo.identityCard.value && detailInfo.identityCard.value.split(',')[1] ? detailInfo.identityCard.value.split(',')[1].split(',') : []">
                      <div><img :src="detailInfo.identityCard.value.split(',')[1]"></div>
                    </viewer>
                    <div class="operateBtn" v-if="detailInfo.merchantInfo[2].isEdit">
                      <el-button type="text" size="small" @click="showBackCardCropper">点击上传</el-button>
                      <el-button size="small" type="text" @click="deleteBackImg">删除</el-button>
                    </div>
                    <div class="imageBottom">法人身份证反面</div>
                  </div>
                </el-col>
                <el-col :xs="12" :sm="12" :md="8" :lg="6" :xl="4" v-if="detailInfo.license.value || this.detailInfo.merchantInfo[2].isEdit">
                  <div class="imgArea">
                    <!--<img :src="detailInfo.license.value.split(',')[0]"/>-->
                    <viewer :images="detailInfo.license.value ? detailInfo.license.value.split(',') : []">
                      <div><img :src="detailInfo.license.value"></div>
                    </viewer>
                    <div class="operateBtn" v-if="detailInfo.merchantInfo[2].isEdit">
                      <el-button type="text" size="small" @click="showLicenseCropper">点击上传</el-button>
                      <el-button size="small" type="text" @click="deleteFrontOpenImg">删除</el-button>
                    </div>
                    <div class="imageBottom">营业执照正面</div>
                  </div>
                </el-col>
                <el-col :xs="12" :sm="12" :md="8" :lg="6" :xl="4" v-if="(detailInfo && detailInfo.merchantInfo[2].value) || this.detailInfo.merchantInfo[2].isEdit">
                  <div class="imgArea">
                    <viewer :images="detailInfo.logo ? detailInfo.logo.split(',') : []">
                      <div><img :src="detailInfo.logo"></div>
                    </viewer>
                    <!--<img :src="this.detailInfo.merchantInfo[0].value" />-->
                    <div class="operateBtn" v-if="detailInfo.merchantInfo[2].isEdit">
                      <el-button type="text" size="small" @click="showImageCropper">点击上传</el-button>
                      <el-button size="small" type="text" @click="deleteLogo">删除</el-button>
                    </div>
                    <div class="imageBottom">门头/logo</div>
                  </div>
                </el-col>
              </el-row>
            </div>
          </el-card>
          <el-card class="jxf-table-card mt10">
            <div slot="header" class="clearfix">
              <span>其他资质</span>
            </div>
            <div class="listArea">
              <el-row :gutter="10" >
                <el-col :xs="12" :sm="12" :md="8" :lg="6" :xl="4" v-for="(img, index) in detailInfo.otherQualification.value.split(',')" :key="index" v-if="detailInfo.otherQualification.value" style="margin-bottom: 10px">
                  <div class="imgArea">
                    <viewer :images="detailInfo.otherQualification.value ? detailInfo.otherQualification.value.split(',') : []">
                      <div>
                        <img :src="detailInfo.otherQualification.value.split(',')[index]">
                      </div>
                    </viewer>
                    <div class="operateBtn" v-if="detailInfo.merchantInfo[2].isEdit">
                      <el-button size="small" type="text" @click="deleteOtherImg(index)">删除</el-button>
                    </div>
                    <!--<img :src="this.detailInfo.merchantInfo[0].value" />-->
                    <div class="imageBottom">其他资质{{index + 1}}</div>
                  </div>
                </el-col>
                <el-col :xs="12" :sm="12" :md="8" :lg="6" :xl="4" style="margin-bottom: 10px" v-if="detailInfo.merchantInfo[2].isEdit && detailInfo.otherQualification.value.split(',').length < 20">
                  <el-button size="small" type="primary" @click="showOtherCardCropper">点击上传</el-button>
                </el-col>
              </el-row>
            </div>
          </el-card>
          <el-card class="jxf-table-card mt10" v-if="detailInfo.status === 1">
            <div slot="header" class="clearfix">
              <span>审核记录</span>
            </div>
            <div class="listArea">
              <jxf-datalist :info="detailInfo.recording" :lineNum="2">
                <template slot="userName" slot-scope="otherInfo">
                  <div class="jxf-flex-start">
                    {{otherInfo.info.value}}
                  </div>
                </template>
                <template slot="createTime" slot-scope="otherInfo">
                  <div class="jxf-flex-start">
                    {{otherInfo.info.value ? FormatDate.timeFormat(otherInfo.info.value) : ""}}
                  </div>
                </template>
                <template slot="result" slot-scope="otherInfo">
                  <div class="jxf-flex-start">
                    {{otherInfo.info.value == 1 ? "已通过" : "已驳回" }}
                  </div>
                </template>
                <template slot="content" slot-scope="otherInfo">
                  <div class="jxf-flex-start">
                    {{otherInfo.info.value}}
                  </div>
                </template>
              </jxf-datalist>
            </div>
          </el-card>
        </el-form>
        <div class="btn-area" v-if="detailInfo.merchantInfo[2].isEdit">
          <el-button type="primary" @click="editSave" :loading="isSuccess">保存</el-button>
        </div>
      </div>
      <MerchantNotPass :isShowDetail.sync="isShowDisableBuyer" :dataInfo="disableInfo" :id="merchantId" @goPrewView="goReviewBack"></MerchantNotPass>
      <MerchantPass :isShowDetail.sync="isShowAbleBuyer" :dataInfo="ableInfo" :id="merchantId" :title="subTitle" @goPrewView="goReviewBack"></MerchantPass>
      <Setting :isShowDetail.sync="isShowFenSetting" :title="subSettingTitle" :dataInfo="inInfoList" :userType="userType" :total="total" @getValue="getValue"></Setting>

      <DisableBuyer :isShowDetail.sync="isShowMerchant" :dataInfo="disableMerchantInfo" :url="merchantStatustUrl" :id="MerchantUserId" @fresh="goPreviewBack"></DisableBuyer>
      <AbleBuyer :isShowDetail.sync="isShowAbleMerchant" :dataInfo="ableMerchantInfo" :url="merchantStatustUrl" :id="MerchantUserId" @fresh="goPreviewBack"></AbleBuyer>
      <jxf-cropper
        :uploadUrl="upload"
        :isShowCropper.sync="isShowCropper"
        :tCropWidth="tCropWidth"
        :tCropHeight="tCropHeight"
        :dealImage.sync="dealImage"
        @getChangedImage="getChangeImage"
        :dataSize="5"></jxf-cropper>
    </div>
    <Log v-if="isShowLog" :dataInfo="logData" @goPreview="goMerchantPage"></Log>
  </div>
</template>

<script>
  import formatMoney from '@/assets/js/formatMoney'
  import FormatDate from '@/assets/js/formatDate'
  import logo from "@/assets/logo.png"
  import Setting from './Setting'
  import MerchantNotPass from './MerchantNotPass'
  import MerchantPass from './MerchantPass'
  import DisableBuyer from './DisableBuyer'
  import AbleBuyer from './AbleBuyer'
  import Log from './Log'
  export default {
    name: "MerchantReview",
    props: {
      title: {
        type: String,
        default: "去审核"
      },
      dataInfo: {
        type: Object,
        default: () => {}
      }
    },
    components: { MerchantNotPass, MerchantPass, Setting, DisableBuyer, AbleBuyer, Log },
    data() {
      return {
        isShowLog: false,
        logData: {
          userId: null,
          page: 1
        },
        // 控制按钮显示
        isShowBtns: true,
        // 裁剪
        isShowCropper: false,
        tCropWidth: 800,
        tCropHeight: 800,
        dealImage: '',
        currentImage: '',
        isSuccess: false,
        subTitle: "",
        agentId: "",
        salesmanId: "",
        channelDealerId: "",
        merchantStatustUrl: apis.user.merchantStatus,
        merchantId: this.dataInfo.id,
        isShowDisableBuyer: false,
        isShowAbleBuyer: false,
        isShowMerchant: false,
        isShowAbleMerchant: false,
        disableMerchantInfo: {},
        ableMerchantInfo: {},
        supplierStatustUrl: "",
        MerchantUserId: this.dataInfo.merchantId,
        disableInfo: {},
        ableInfo: {},
        inInfoList: {},
        logo: logo,
        total: 0,
        userType: 2,
        // 显示分公司弹出框
        isShowFenSetting: false,
        subSettingTitle: "",
        FormatDate: FormatDate,
        rules: {

        },
        formatMoney: formatMoney,
        upload: apis.user.supplierUpload,
        detailInfo: this.dataInfo,
        fileList: this.detailInfo ? this.detailInfo.otherQualification.value.split(',') : [],
        deliveryIds: this.dataInfo && this.dataInfo.deliveryIds ? this.dataInfo.deliveryIds.split(',') : [],
        header: {
          token: JSON.parse(window.localStorage.adminLogin).token
        } ,
        pickerStart: {
          disabledDate: time => {
            if(this.detailInfo.identityCardEnd) {
              return new Date(time).getTime() > new Date(this.detailInfo.identityCardEnd).getTime()
            }
          }
        },
        pickerEnd: {
          disabledDate: time => {
            if(this.detailInfo.identityCardStart) {
              return new Date(time).getTime() < new Date(this.detailInfo.identityCardStart).getTime()
            }
          }
        },
      }
    },
    methods: {
      // 审核|通过驳回返回该页面
      goReviewBack() {
        this.detailInfo.merchantInfo.map((item, index) => {
          if(item.hasOwnProperty("isEdit")) {
            item.isEdit = false
          }
        });
        this.detailInfo.otherInfo.map((item, index) => {
          if(item.hasOwnProperty("isEdit")) {
            item.isEdit = false
          }
        });
        this.isShowBtns = false;
      },

      /**** 裁剪图片完进行图片回显 ****/
      getChangeImage(val) {
        switch (this.currentImage) {
          case '1':
            if(this.detailInfo.identityCard.value && this.detailInfo.identityCard.value.split(',').length > 1) {
              this.detailInfo.identityCard.value = val + ',' + this.detailInfo.identityCard.value.split(',')[1]
            } else {
              this.detailInfo.identityCard.value = val
            }
            break;
          case '2':
            if(this.detailInfo.identityCard.value && this.detailInfo.identityCard.value.split(',').length > 0) {
              this.detailInfo.identityCard.value =  this.detailInfo.identityCard.value.split(',')[0] + ',' + val
            } else {
              this.detailInfo.identityCard.value = ' ' + ',' + val
            }
            break;
          case '3':
            this.detailInfo.license.value = val;
            break;
          case '4':
            this.detailInfo.logo = val;
            break;
          case '5':
            let list = this.detailInfo.otherQualification.value ? this.detailInfo.otherQualification.value.split(',') : []
            list.push(val);
            this.detailInfo.otherQualification.value = list.join(',');
            break;
          default:
            break;
        }
      },

      showFrontCardCropper() {
        this.dealImage = this.detailInfo.identityCard.value ? this.detailInfo.identityCard.value.split(',')[0] : '' ;
        this.currentImage = '1';
        this.isShowCropper = true;
      },

      showBackCardCropper() {
        this.dealImage = this.detailInfo.identityCard.value && this.detailInfo.identityCard.value.split(',').length > 1 ? this.detailInfo.identityCard.value.split(',')[1] : '' ;
        this.currentImage = '2';
        this.isShowCropper = true;
      },

      showLicenseCropper() {
        this.dealImage = this.detailInfo.license.value ;
        this.currentImage = '3';
        this.isShowCropper = true;
      },

      showImageCropper() {
        this.dealImage = this.detailInfo.logo;
        this.currentImage = '4';
        this.isShowCropper = true;
      },

      showOtherCardCropper() {
        this.dealImage = '';
        this.currentImage = '5';
        this.isShowCropper = true;
      },

      // 重置密码
      resetPwd() {
        let data = {
          codeType: 7,
          roleType: '',
          telphone: this.detailInfo.merchantInfo[0].value
        };
        this.$confirm('此操作将重置此账户密码, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          ajax.post(apis.common.sendCode, data).then(res => {
            if(res.code === "10000000") {
              this.$message({
                type: 'success',
                message: '重置密码成功!'
              });
            } else {
              this.$message.error(res.message)
            }
          });
        }).catch(() => {

        });
      },

      // 验证身份证号是否合法
      isCardNo(card, title) {
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if(reg.test(card) === false)
        {
          this.$notify({
            title: '警告',
            message: title + '不合法',
            type: 'warning'
          });
          return true;
        }
        return false;
      },

      // 禁用采购商
      showNotMerchant() {
        this.disableMerchantInfo.name = this.detailInfo.enterpriseName
        this.isShowMerchant = true;
      },

      // 解禁采购商\
      showMerchant() {
        this.ableMerchantInfo.name = this.detailInfo.enterpriseName
        this.isShowAbleMerchant = true;
      },

      goPreviewBack() {
        if(this.detailInfo.accountStatus == 0) {
          this.detailInfo.accountStatus = 1
        } else {
          this.detailInfo.accountStatus = 0;
        }
      },

      // 获取登陆日志
      getLog() {
         this.logData = {
            userId: this.detailInfo.userId,
            page: 1
          };
        // this.$router.push({name: '/Role/log',params: data});
        this.isShowLog = true;
      },

      goMerchantPage() {
        this.logData = {
          userId: null,
          page: 1
        };
        this.isShowLog = false
      },
      // 返回上一个页面
      goListPage() {
        this.agentId = "";
        this.salesmanId = "";
        this.channelDealerId = "";
        this.$emit('goBack')
      },

      // 显示分公司弹出框
      showFenSetting() {
        this.subSettingTitle = "设置分公司"
        let data = {
          userType: 2,
          userName: "",
          pageNum: 1,
          pageSize: 10,
          cityId: this.dataInfo.cityId
        };
        this.userType = 2;
        ajax.post(apis.user.getBranchList, data).then(result => {
          if(result.code == "10000000") {
            this.inInfoList = result.data;
            this.total = result.data.total
            this.isShowFenSetting = true;
          } else {
            this.$message.error(result.message)
          }
        })
      },

      // 设置业务员弹出框
      showSalemanSetting() {
        this.subSettingTitle = "设置业务员";
        let data = {
          userType: 6,
          userName: "",
          pageNum: 1,
          pageSize: 10,
          cityId: this.dataInfo.cityId
        };
        this.userType = 6;
        ajax.post(apis.user.getBranchList, data).then(result => {
          if(result.code === "10000000") {
            this.inInfoList = result.data;
            this.total = result.data.total
            this.isShowFenSetting = true;
          } else {
            this.$message.error(result.message)
          }
        })
      },

      // 设置渠道商弹出框
      showChannelSetting() {
        this.subSettingTitle = "设置渠道商"
        let data = {
          userType: 7,
          userName: "",
          pageNum: 1,
          pageSize: 10,
          cityId: this.dataInfo.cityId
        };
        this.userType = 7;
        ajax.post(apis.user.getBranchList, data).then(result => {
          if(result.code === "10000000") {
            this.inInfoList = result.data;
            this.total = result.data.total
            this.isShowFenSetting = true;
          } else {
            this.$message.error(result.message)
          }
        })
      },

      // 所属分公司--2 对接业务员--6 所属渠道商--7
      getValue(val) {
        if(val.userType == 2) {
          this.agentId = val.id;
          this.detailInfo.merchantInfo[3].value = val.userName
        }
        if(val.userType == 6) {
          this.salesmanId = val.id;
          this.detailInfo.merchantInfo[5].value = val.userName
        }
        if(val.userType == 7) {
          this.channelDealerId = val.id;
          this.detailInfo.merchantInfo[7].value = val.userName
        }
      },
      // 审核通过
      showPass() {
        this.subTitle = "审核通过";
        let isCardNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        let certificateValidity = this.detailInfo.identityCardStart + '-' + this.detailInfo.identityCardEnd;
        if(!this.detailInfo.identityCardStart || !this.detailInfo.identityCardEnd) {
          this.$notify({
            title: '警告',
            message: '法人身份证有效期信息填写完整',
            type: 'warning'
          });
          return;
        }
        let data = {
          agentId: this.agentId,
          certificateValidity: certificateValidity,
          contact: this.detailInfo.merchantInfo[4].value,
          detailAdress: this.detailInfo.merchantInfo[6].value,
          enterpriseAuthId: this.detailInfo.enterpriseAuthId,
          enterpriseName: this.detailInfo.merchantInfo[2].value,
          entityId: "",
          id: this.detailInfo.id,
          idNumber: this.detailInfo.otherInfo[3].value,
          identityCardImage: this.detailInfo.identityCard.value,
          channelDealerId: this.channelDealerId,
          legalName: this.detailInfo.otherInfo[2].value,
          licenseImage: this.detailInfo.license.value,
          logo: this.detailInfo.logo,
          otherCertificate: "",
          otherQualification: this.detailInfo.otherQualification.value,
          registrantIdNum: this.detailInfo.otherInfo[1].value,
          registrantName: this.detailInfo.otherInfo[0].value,
          salesmanId: this.salesmanId,
          userId: this.detailInfo.userId,
          creditCode: this.detailInfo.merchantInfo[8].value
        };
        // 注册主体人的名称
        if(!data.registrantName) {
          this.$notify({
            title: '警告',
            message: '注册主体人的名称必填',
            type: 'warning'
          });
          return;
        }
        if(!data.creditCode) {
          this.$notify({
            title: '警告',
            message: '社会代码的名称必填',
            type: 'warning'
          });
          return;
        }
        // 注册主体人证件号
        if(!data.registrantIdNum) {
          this.$notify({
            title: '警告',
            message: '注册主体人证件号必填',
            type: 'warning'
          });
          return;
        }

        // 企业名称必填
        if(!data.enterpriseName) {
          this.$notify({
            title: '警告',
            message: '企业名称必填',
            type: 'warning'
          });
          return;
        }
        // 配送区域必填
        if(!this.detailInfo.merchantInfo[3].value) {
          this.$notify({
            title: '警告',
            message: '所属子公司不能为空！请先补全所属子公司的信息早来审核',
            type: 'warning'
          });
          return;
        }
        if(!new RegExp(isCardNo).test(data.registrantIdNum)) {
          this.$notify({
            title: '警告',
            message: '注册主体人证件号格式不对',
            type: 'warning'
          });
          return;
        }
        // 法人姓名必填
        if(!data.legalName) {
          this.$notify({
            title: '警告',
            message: '法人姓名必填',
            type: 'warning'
          });
          return;
        }
        // 法人身份证必填
        if(!data.idNumber) {
          this.$notify({
            title: '警告',
            message: '法人身份证必填',
            type: 'warning'
          });
          return;
        }
        if(!new RegExp(isCardNo).test(data.idNumber)) {
          this.$notify({
            title: '警告',
            message: '法人身份证格式不对',
            type: 'warning'
          });
          return;
        }
        // 原始资料必填
        if(data.identityCardImage && data.identityCardImage.split(',')[0] && data.identityCardImage.split(',')[1] && data.licenseImage && data.logo) {

        } else {
          this.$notify({
            title: '警告',
            message: '原始资料必须补充完整',
            type: 'warning'
          });
          return;
        }
        this.ableInfo = {
          name: this.detailInfo.merchantInfo[2].value
        };
        this.isShowAbleBuyer = true;
      },
      showNotPass() {
        this.subTitle = "审核驳回";
        this.disableInfo = {
          name: this.detailInfo.merchantInfo[2].value
        };
        this.isShowDisableBuyer = true;
      },
      // 删除其它资质
      deleteOtherImg(index) {
        let array = this.detailInfo.otherQualification.value.split(',');
        if(this.detailInfo.otherQualification.value && this.detailInfo.otherQualification.value.split(',')) {
          array.splice(index, 1);
          this.detailInfo.otherQualification.value = array.join(',')
        }
      },
      // 删除正面法人
      deleteFrontImg() {
        if(this.detailInfo.identityCard.value && this.detailInfo.identityCard.value.split(',').length === 2) {
          this.detailInfo.identityCard.value = "" + "," + this.detailInfo.identityCard.value.split(',')[1]
        } else {
          this.detailInfo.identityCard.value = ""
        }
      },
      // 删除反面法人
      deleteBackImg() {
        if(this.detailInfo.identityCard.value && this.detailInfo.identityCard.value.split(',').length > 0) {
          this.detailInfo.identityCard.value = this.detailInfo.identityCard.value.split(',')[0] + "," + ""
        } else {
          this.detailInfo.identityCard.value = " " + "," + ""
        }
      },
      // 营业照正面法人
      deleteFrontOpenImg() {
        if(this.detailInfo.license.value && this.detailInfo.license.value.split(',').length === 2) {
          this.detailInfo.license.value = "" + "," + this.detailInfo.license.value.split(',')[1]
        } else {
          this.detailInfo.license.value = ""
        }
      },
      // 营业照反面法人
      deleteBackOpenImg() {
        if(this.detailInfo.license.value && this.detailInfo.license.value.split(',').length > 0) {
          this.detailInfo.license.value = this.detailInfo.license.value.split(',')[0] + "," + ""
        } else {
          this.detailInfo.license.value = " " + "," + ""
        }
      },

      // 删除门头/logo
      deleteLogo() {
        this.detailInfo.logo = ''
      },

      // 验证身份证号是否合法
      isCardNo(card, title) {
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if(reg.test(card) === false)
        {
          this.$notify({
            title: '警告',
            message: title + '不合法',
            type: 'warning'
          });
          return true;
        }
        return false;
      },

      // 查看资金账户
      watchAccountInfo() {
        let data = {
          telphone: this.detailInfo.merchantInfo[0].value
        };
        this.$router.push({name: 'merchantCapitalAccount',params: data});
      },

      // 保存
      editSave() {
        let isCardNo = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        let certificateValidity = this.detailInfo.identityCardStart + '-' + this.detailInfo.identityCardEnd;
        if(!this.detailInfo.identityCardStart || !this.detailInfo.identityCardEnd) {
          this.$notify({
            title: '警告',
            message: '法人身份证有效期信息填写完整',
            type: 'warning'
          });
          return;
        }
        let data = {
          agentId: this.agentId,
          certificateValidity: certificateValidity,
          contact: this.detailInfo.merchantInfo[4].value,
          detailAdress: this.detailInfo.merchantInfo[6].value,
          enterpriseAuthId: this.detailInfo.enterpriseAuthId,
          enterpriseName: this.detailInfo.merchantInfo[2].value,
          entityId: "",
          id: this.detailInfo.id,
          idNumber: this.detailInfo.otherInfo[3].value,
          identityCardImage: this.detailInfo.identityCard.value,
          channelDealerId: this.channelDealerId,
          legalName: this.detailInfo.otherInfo[2].value,
          licenseImage: this.detailInfo.license.value,
          logo: this.detailInfo.logo,
          otherCertificate: "",
          otherQualification: this.detailInfo.otherQualification.value,
          registrantIdNum: this.detailInfo.otherInfo[1].value,
          registrantName: this.detailInfo.otherInfo[0].value,
          salesmanId: this.salesmanId,
          userId: this.detailInfo.userId,
          creditCode: this.detailInfo.merchantInfo[8].value
        };

        // 注册主体人的名称
        if(!data.registrantName) {
          this.$notify({
            title: '警告',
            message: '注册主体人的名称必填',
            type: 'warning'
          });
          return;
        }
        if(!data.creditCode) {
          this.$notify({
            title: '警告',
            message: '社会代码的名称必填',
            type: 'warning'
          });
          return;
        }

        // 注册主体人证件号
        if(!data.registrantIdNum) {
          this.$notify({
            title: '警告',
            message: '注册主体人证件号必填',
            type: 'warning'
          });
          return;
        }

        // 企业名称必填
        if(!data.enterpriseName) {
          this.$notify({
            title: '警告',
            message: '企业名称必填',
            type: 'warning'
          });
          return;
        }

        if(!new RegExp(isCardNo).test(data.registrantIdNum)) {
          this.$notify({
            title: '警告',
            message: '注册主体人证件号格式不对',
            type: 'warning'
          });
          return;
        }

        // 法人姓名必填
        if(!data.legalName) {
          this.$notify({
            title: '警告',
            message: '法人姓名必填',
            type: 'warning'
          });
          return;
        }

        // 法人身份证必填
        if(!data.idNumber) {
          this.$notify({
            title: '警告',
            message: '法人身份证必填',
            type: 'warning'
          });
          return;
        }

        if(!new RegExp(isCardNo).test(data.idNumber)) {
          this.$notify({
            title: '警告',
            message: '法人身份证格式不对',
            type: 'warning'
          });
          return;
        }

        // 原始资料必填
        if(data.identityCardImage && data.identityCardImage.split(',')[0] && data.identityCardImage.split(',')[1] && data.licenseImage && data.logo) {

        } else {
          this.$notify({
            title: '警告',
            message: '原始资料必须补充完整',
            type: 'warning'
          });
          return;
        }

        this.isSuccess = true;
        ajax.post(apis.user.merchantEidt, data).then(res => {
          if(res.code === "10000000") {
            this.$message({
              type: 'success',
              message: '保存成功'
            });
            this.detailInfo.merchantInfo.map((item, index) => {
              if(item.hasOwnProperty("isEdit")) {
                item.isEdit = false
              }
            });
            this.detailInfo.otherInfo.map((item, index) => {
              if(item.hasOwnProperty("isEdit")) {
                item.isEdit = false
              }
            })
            // this.$emit('fresh')
          } else {
            this.$message.error(res.message)
          }
          this.isSuccess = false;
        })
      },

      // 编辑
      editInfo() {
        this.detailInfo.merchantInfo.map((item, index) => {
          if(item.hasOwnProperty("isEdit")) {
            item.isEdit = true
          }
        });
        this.detailInfo.otherInfo.map((item, index) => {
          if(item.hasOwnProperty("isEdit")) {
            item.isEdit = true
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .imageBottom {
    height: 40px;
    line-height: 40px;
    width: 140px;
    text-align: center;
    background: rgba(249, 250, 252, 1);
    border: 1px solid rgba(228, 228, 228, 1);
  }
  .operateBtn {
    display: flex;
    justify-content: space-between;
    padding: 3px 10px;
    width: 140px;
    background: #f9f9f9;
    box-sizing: border-box;
  }
  .imgArea {
    margin-top: 10px;
    width: 140px;
    border: 1px solid rgba(228, 228, 228, 1);
    img {
      margin-left: 10px;
    }
  }

  .btn-area {
    margin-top: 20px;
  }
</style>
